package org.zfes.snowier.cloud.zbss.layer.tc.biz.service.impl;

import java.util.Map;
import java.util.Optional;
import org.zfes.snowier.core.data.DataSet;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.zfes.snowier.core.util.ZBeanUtil;
import org.zfes.snowier.core.util.ZAlert;
import org.zfes.snowier.core.idcenter.IDGenerator;
import org.zfes.snowier.common.dao.params.ParamMap;
import org.zfes.snowier.cloud.zbss.layer.tc.biz.service.ISalaryPercentageService;
import org.zfes.snowier.cloud.zbss.layer.tc.biz.dao.SalaryPercentageMapper;
import org.zfes.snowier.cloud.zbss.layer.tc.biz.model.SalaryPercentage;

@Service
public class SalaryPercentageServiceImpl implements ISalaryPercentageService{
 	@Autowired
	private SalaryPercentageMapper salaryPercentageMapper;
	
	@Transactional(rollbackFor=Exception.class)
 	@Override
	public void createSalaryPercentage(SalaryPercentage salaryPercentage) {
		ZBeanUtil.validateBean(salaryPercentage);
		salaryPercentage.setId(IDGenerator.genLongId());
		salaryPercentageMapper.insertSelective(salaryPercentage);
	}
	@Transactional(rollbackFor=Exception.class,readOnly=true)
	@Override
	public Optional<SalaryPercentage> loadSalaryPercentageById(Long id) {
		if(id!=null){
			return Optional.ofNullable(salaryPercentageMapper.selectByPrimaryKey(id));
		}
		return Optional.empty();
		
	}
	@Transactional(rollbackFor=Exception.class)
	@Override
	public void updateSalaryPercentage(SalaryPercentage salaryPercentage) {
		ZBeanUtil.validateBean(salaryPercentage);
		salaryPercentageMapper.updateByPrimaryKeySelective(salaryPercentage);
	}
	
	@Transactional(rollbackFor=Exception.class)
	@Override
	public void deletSalaryPercentage(Long id) {
		if(id!=null){
			salaryPercentageMapper.deleteByPrimaryKey(id);
			return;
		}
		ZAlert.Error("请选择要删除的数据");
		
	}
	
	@Transactional(rollbackFor=Exception.class,readOnly=true)
	@Override
	public DataSet loadSalaryPercentageDataSet(Map<String, Object> params) {
		ParamMap pm=ParamMap.filterParam(params);
		pm.getObj("caseNum").ifPresent(v->pm.updateParam("caseNum", "%"+v+"%"));
		pm.getObj("clientName").ifPresent(v->pm.updateParam("clientName", "%"+v+"%"));
		
		DataSet ds=DataSet.newDS(salaryPercentageMapper.selectListCount(pm), salaryPercentageMapper.selectList(pm));
		return ds;
	}
	
}